package de.unihannover.hci.portraitquiz.adapter;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;

import de.unihannover.hci.portraitquiz.R;
import de.unihannover.hci.portraitquiz.model.Score;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ScoreArrayAdapter extends ArrayAdapter<Score> {

	private List<Score> scores;
	private Context context;

	public ScoreArrayAdapter(Context context, List<Score> scores) {
		super(context, R.layout.highscore_rowlayout, scores);
		this.scores = scores;
		this.context = context;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.highscore_rowlayout, parent, false);

		Score score = scores.get(position);
		TextView rankView = (TextView) rowView.findViewById(R.id.rank);
		rankView.setText(position + 1 + ")");

		TextView dateView = (TextView) rowView.findViewById(R.id.date);
		SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy  hh:mm aa", Locale.US);
		dateView.setText(formatter.format(score.getDatetime().getTime()));

		TextView scoreView = (TextView) rowView.findViewById(R.id.score);
		scoreView.setText(score.getPoints() + "");

		return rowView;
	}

	@Override
	public boolean isEnabled(int position) {
		return false;
	}
}
